@echo off
chcp 65001 >nul
echo 快速修复APK安装问题
echo ========================

echo.
echo 正在修复构建配置...

REM 更新build.gradle.kts以解决安装问题
(
echo plugins {
echo     alias^(libs.plugins.android.application^)
echo     alias^(libs.plugins.kotlin.android^)
echo }
echo.
echo android {
echo     namespace = "com.example.myapplication"
echo     compileSdk = 34
echo.
echo     defaultConfig {
echo         applicationId = "com.example.myapplication"
echo         minSdk = 21
echo         targetSdk = 34
echo         versionCode = 1
echo         versionName = "1.0"
echo         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
echo         multiDexEnabled = true
echo     }
echo.
echo     buildTypes {
echo         release {
echo             isMinifyEnabled = false
echo             isShrinkResources = false
echo             proguardFiles^(getDefaultProguardFile^("proguard-android-optimize.txt"^), "proguard-rules.pro"^)
echo         }
echo     }
echo     compileOptions {
echo         sourceCompatibility = JavaVersion.VERSION_11
echo         targetCompatibility = JavaVersion.VERSION_11
echo     }
echo     kotlinOptions {
echo         jvmTarget = "11"
echo     }
echo     testOptions {
echo         unitTests.isIncludeAndroidResources = false
echo         unitTests.all { it.enabled = false }
echo     }
echo }
echo.
echo dependencies {
echo     implementation^(libs.androidx.core.ktx^)
echo     implementation^(libs.androidx.appcompat^)
echo     implementation^("androidx.multidex:multidex:2.0.1"^)
echo     implementation^("androidx.recyclerview:recyclerview:1.3.2"^)
echo     implementation^("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"^)
echo     implementation^("com.google.android.material:material:1.11.0"^)
echo     implementation^("org.java-websocket:Java-WebSocket:1.5.4"^)
echo     implementation^("com.google.firebase:firebase-messaging:23.4.0"^)
echo     implementation^("com.google.firebase:firebase-analytics:21.5.0"^)
echo     implementation^("com.squareup.okhttp3:okhttp:4.12.0"^)
echo     implementation^("com.squareup.okhttp3:logging-interceptor:4.12.0"^)
echo     implementation^("com.google.code.gson:gson:2.10.1"^)
echo     implementation^("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"^)
echo     implementation^("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"^)
echo     implementation^("androidx.work:work-runtime-ktx:2.9.0"^)
echo }
echo.
echo tasks.withType^<Test^> { enabled = false }
) > "app\build.gradle.kts"

echo 重新构建APK...
call gradlew clean assembleRelease

if exist "app\release\app-release.apk" (
    echo.
    echo ✓ APK构建成功！
    echo.
    echo 安装说明：
    echo 1. 确保设备Android版本 ≥ 5.0
    echo 2. 开启"未知来源"应用安装权限
    echo 3. 如果无法安装，先卸载旧版本
    echo.
    echo APK位置: app\release\app-release.apk
) else (
    echo.
    echo ✗ APK构建失败，请检查错误信息
)

pause 